<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="text" class="yhm"><input type="checkbox" class="jz" onclick="bc()">记住用户名
</body>
</html>
<script>
    var yhm=document.querySelector('.yhm')
    var jz=document.querySelector('.jz')
    function bc(){
        if(this.checkbox==true){
            localStorage.setItem('username',yhm.value);
        }else{
            localStorage.removeItem('username');
        }
        
    }
    if(localStorage.getItem(yhm)){
        yhm.value=localStorage.getItem('yhm')
        jz.checkbox=true
    }
</script>